package com.sam.im.sms.index.activitys;

import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.sam.im.sms.R;
import com.sam.im.sms.base.BaseActivity;
import com.sam.im.sms.setting.SMSSettingImpl;
import com.sam.im.sms.setting.Setting;

/**
 * 描述
 * liuyucheng
 * Created By 刘育成 on 2019/6/4.
 */
public class RuleActivity extends BaseActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {

    private LinearLayout mLlLayout;
    private TextView mTvBack;
    private TextView mTextView;
    private Switch mIsIntelligent;
    private Switch mIsBlackList;
    private Switch mIsStranger;

    boolean stranger;
    boolean blackList;
    boolean intelligent;
    Setting mSetting;


    @Override
    public int getContentViewId() {
        return R.layout.activity_rule;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        mSetting = SMSSettingImpl.getInstance();
        initViews();
        updataUI();
    }

    private void updataUI() {
        stranger = mSetting.isStranger("stranger");
        blackList = mSetting.isBlackList("blackList");
        intelligent = mSetting.isIntelligent("intelligent");
        mIsBlackList.setChecked(blackList);
        mIsIntelligent.setChecked(intelligent);
        mIsStranger.setChecked(stranger);
        mIsStranger.setOnCheckedChangeListener(this::onCheckedChanged);
        mIsIntelligent.setOnCheckedChangeListener(this::onCheckedChanged);
        mIsBlackList.setOnCheckedChangeListener(this::onCheckedChanged);
    }

    private void initViews() {
        mLlLayout = findViewById(R.id.ll_layout);
        mTvBack = findViewById(R.id.tv_back);
        mTextView = findViewById(R.id.textView);
        mIsIntelligent = findViewById(R.id.is_intelligent);
        mIsBlackList = findViewById(R.id.is_black_list);
        mIsStranger = findViewById(R.id.is_stranger);
        mTvBack.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_back:
                finish();
                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            //智能拦截
            case R.id.is_intelligent:
                mSetting.setIntelligent("intelligent", isChecked);
                break;
            //拦截黑名单
            case R.id.is_black_list:
                mSetting.setIntelligent("blackList", isChecked);
                break;
            //拦截陌生人
            case R.id.is_stranger:
                mSetting.setIntelligent("stranger", isChecked);
                break;
        }
    }
}
